import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;

import com.corpit.seaasia.R;
import com.corpit.seaasia.tools.CommonFunction;



/*1、在程序启动页面中添加一个ImageView,通过它来获取手机的分辨率*/
imageView = (ImageView) view.findViewById(R.id.start_iv);
ViewTreeObserver vto = imageView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
	@Override
	public void onGlobalLayout() {
		imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
		//取得宽高
		int height = imageView.getHeight();
		int width = imageView.getWidth();
		//将宽高存为全局变量
		Global.point = new Point(width, height);
	}
});

/*2、在CommonFunction中添加通用方法*/
public static final float WIDTH = 1080;// with模板指定的宽
public static final float HEIGHT = 1920;// height模板指定的高
/**
 ***************************************************** 
 * 方法简介: 取得现有分辨率的宽
 * @param width 模板的实现的宽
 * @return 换算出现在分辨率的宽
 ***************************************************** 
 */
public static int getImageWidth(int width) {
	float scale = Constants.WIDTH / Global.point.x;// 求出比例
	float imageWidth = width / scale;
	return (int) imageWidth;
}

/**
 ***************************************************** 
 * 方法简介: 取得现有分辨率的高
 * @param width 模板的实现的高
 * @return 换算出现在分辨率的高
 ***************************************************** 
 */
public static int getImageHeight(int height) {
	float scale = Constants.HEIGHT / Global.point.y;// 求出比例
	float imageHeight = height / scale;
	return (int) imageHeight;
}

/*3、在程序中调用*/
ImageView banner = (ImageView) parent.findViewById(R.id.banner);
LayoutParams ps = (LayoutParams) banner.getLayoutParams();
ps.height = CommonFunction.getImageHeight(60);
//ps.width=CommonFunction.getImageWidth(1080);
banner.setLayoutParams(ps);
